//
//  main.m
//  面试题
//
//  Created by Toj on 7/28/21.
//

#import <Foundation/Foundation.h>
void sort(int array[]);

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        int array[] = { 2, 8, 3, 7, 5, 6 };
        int length = sizeof(array) / sizeof(int);
        for (int i = 1; i < length; i++) {
            int numI = array[i];
            
            for (int j = i-1; j >= 0; j--) {
                int numJ = array[j];
                if (numJ > numI) {
                    array[j+1] = numJ;
                    if (j == 0) {
                        array[j] = numI;
                    }
                    continue;
                }
                
                array[j+1] = numI;
                break;
            }
            
            
        }
        for (int i = 0; i < length; i++) {
            int numI = array[i];
            NSLog(@"%d", numI);
        }
    }
    return 0;
}
/*
 void sort(int aArray[7]) {
 int array[] = aArray;
 int length = sizeof(array)/ sizeof(int);
 if (length <= 1) { return; }
 
 int index, exc;
 for (int i = 0; i < length-1; i++) {
 index = i;
 // 检索最小值下标
 for (int j = i+1; j <length; j++) {
 if (array[index] > array[j]) index = j;
 }
 // 做交换
 if (index == i) continue;
 exc = array[index];
 array[index] = array[i];
 array[i] = exc;
 }
 
 for (int i = 0; i < length; i++) {
 printf("%d\n", array[i]);
 }
 }
 */
